class Solution(object):
    def maximumBinaryString(self, binary):
        out = list(binary)
        zero_index = -1
        n = len(binary)
        for i in range(n):
            if out[i] == '0':
                if zero_index == -1:
                    zero_index = i
                else:
                    for j in range(zero_index, i):
                        if out[j] == '0':
                            out[j] = '1'
                        else:
                            out[j] = '0'
                            zero_index = j
                            out[i] = '1'
                            break
                    if out[i] == '0':
                        zero_index = i
        return ''.join(out)

